//
//  KaiJiangHallViewController.m
//  HomeDemo
//
//  Created by liGordon on 17/3/30.
//  Copyright © 2017年 ZJNY. All rights reserved.
//

#import "KaiJiangHallViewController.h"
#import "KaiJiangFiveCell.h"
#import "KaiJiangSevenCell.h"
#import "KaiJiangThreeCell.h"
#import "KaiJiangHistoryViewController.h"
static NSString *identifier1 = @"KaiJiangThreeCell";
static NSString *identifier2 = @"KaiJiangFiveCell";
static NSString *identifier3 = @"KaiJiangSevenCell";
@interface KaiJiangHallViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *menuTable;
@property(nonatomic,strong)NSArray *numArr;

@end

@implementation KaiJiangHallViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title=@"开奖";
    _menuTable.delegate = self;
    _menuTable.dataSource = self;
    [_menuTable registerNib:[UINib nibWithNibName:@"KaiJiangSevenCell" bundle:nil] forCellReuseIdentifier:identifier3];
       [_menuTable registerNib:[UINib nibWithNibName:@"KaiJiangFiveCell" bundle:nil] forCellReuseIdentifier:identifier2];
      [_menuTable registerNib:[UINib nibWithNibName:@"KaiJiangThreeCell" bundle:nil] forCellReuseIdentifier:identifier1];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 9;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];// 取消选中
    //其他代码
    if (indexPath.row == 0||indexPath.row == 2||indexPath.row ==4 ||indexPath.row ==7) {
      KaiJiangHistoryViewController *vc =  [[KaiJiangHistoryViewController alloc]init];
        vc.flag = 7;
        vc.numArr = self.numArr;
        PushVC(vc)
    }else if (indexPath.row == 1 || indexPath.row ==3 || indexPath.row == 6 || indexPath.row == 8){
        KaiJiangHistoryViewController *vc = [[KaiJiangHistoryViewController alloc]init];
        vc.flag = 5;
        PushVC(vc)
    }else if (indexPath.row == 5){
        KaiJiangHistoryViewController *vc = [[KaiJiangHistoryViewController alloc]init];
        vc.flag = 3;
        PushVC(vc)
    }
}


-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSDateFormatter *date_formatter = [[NSDateFormatter alloc] init];
         [date_formatter setDateFormat:@"yyyy-MM-dd"];
    
    if (indexPath.row == 0) {
        KaiJiangSevenCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier3];
        cell.titleName.text = @"双色球";
        [cell.imageName setImage:[UIImage imageNamed:@"icon_scq"]];
         cell.numTitle.text = [NSString stringWithFormat:@"%@期",[[self getTimeAndRandom]substringToIndex:12]];
        cell.timeTitle.text =  [date_formatter stringFromDate:[NSDate date]];
        
        self.numArr = cell.numArr;
        NSLog(@"%@",self.numArr);
        return cell;
    }else if (indexPath.row == 1){
        KaiJiangFiveCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier2];
        cell.pushflag = 1;
        cell.titleName.text = @"重庆时时彩";
        cell.numTitle.text = [NSString stringWithFormat:@"%@期",[[self getTimeAndRandom]substringToIndex:12]];
          cell.timeTitle.text =  [date_formatter stringFromDate:[NSDate date]];
        [cell.imageName setImage:[UIImage imageNamed:@"icon_cqssc"]];
        return cell;
    }else if (indexPath.row == 2){
        KaiJiangSevenCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier3];
        cell.titleName.text = @"超级大乐透";
        NSDate*nowDate = [NSDate date];
        NSDate* theDate;
     
            NSTimeInterval  oneDay = -24*60*60*1;  //1天的长度
            theDate = [nowDate initWithTimeIntervalSinceNow: oneDay*2 ];
       cell.timeTitle.text  = [date_formatter stringFromDate:theDate];
          cell.numTitle.text = [NSString stringWithFormat:@"%@期",[[self getYYestTimeAndRandom]substringToIndex:12]];
        [cell.imageName setImage:[UIImage imageNamed:@"icon_cjdlt"]];
        return cell;
    }else if (indexPath.row == 3){
         KaiJiangFiveCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier2];
          cell.pushflag = 1;
        cell.titleName.text = @"PK拾";
        
        NSDate*nowDate = [NSDate date];
        NSDate* theDate;
        
        NSTimeInterval  oneDay = -24*60*60*1;  //1天的长度
        theDate = [nowDate initWithTimeIntervalSinceNow: oneDay*1 ];
        cell.timeTitle.text  = [date_formatter stringFromDate:theDate];
        cell.numTitle.text = [NSString stringWithFormat:@"%@期",[[self getYestTimeAndRandom]substringToIndex:12]];
             cell.numTitle.text = [NSString stringWithFormat:@"%@期",[[self getTimeAndRandom]substringToIndex:12]];
        [cell.imageName setImage:[UIImage imageNamed:@"icon_pks"]];
        return cell;
    }else if (indexPath.row == 4){
        KaiJiangSevenCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier3];
        cell.titleName.text = @"PC蛋蛋";
        NSDate*nowDate = [NSDate date];
        NSDate* theDate;
        
        NSTimeInterval  oneDay = -24*60*60*1;  //1天的长度
        theDate = [nowDate initWithTimeIntervalSinceNow: oneDay*2 ];
        cell.timeTitle.text  = [date_formatter stringFromDate:theDate];
        cell.numTitle.text = [NSString stringWithFormat:@"%@期",[[self getYYestTimeAndRandom]substringToIndex:12]];
 
        [cell.imageName setImage:[UIImage imageNamed:@"icon_pcdd"]];
        return cell;
    }else if (indexPath.row == 5){
        KaiJiangThreeCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier1];
        cell.titleName.text = @"排列三";
            cell.numTitle.text = [NSString stringWithFormat:@"%@期",[[self getTimeAndRandom]substringToIndex:12]];
        cell.timeTitle.text =  [date_formatter stringFromDate:[NSDate date]];

        [cell.imageName setImage:[UIImage imageNamed:@"icon_pl3"]];
        return cell;
    }else if (indexPath.row == 6){
        KaiJiangFiveCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier2];
          cell.pushflag = 1;
        cell.titleName.text = @"排列五";
        cell.timeTitle.text =  [date_formatter stringFromDate:[NSDate date]];

           cell.numTitle.text = [NSString stringWithFormat:@"%@期",[[self getTimeAndRandom]substringToIndex:12]];
        [cell.imageName setImage:[UIImage imageNamed:@"icon_pl5"]];
        return cell;
    }else if (indexPath.row == 7){
        KaiJiangSevenCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier3];
        cell.titleName.text = @"七乐彩";
          cell.numTitle.text = [NSString stringWithFormat:@"%@期",[[self getYestTimeAndRandom]substringToIndex:12]];
        NSDate*nowDate = [NSDate date];
        NSDate* theDate;
        
        NSTimeInterval  oneDay = -24*60*60*1;  //1天的长度
        
        theDate = [nowDate initWithTimeIntervalSinceNow: oneDay*1 ];
        cell.timeTitle.text  = [date_formatter stringFromDate:theDate];
        cell.numTitle.text = [NSString stringWithFormat:@"%@期",[[self getTimeAndRandom]substringToIndex:12]];
        [cell.imageName setImage:[UIImage imageNamed:@"icon_7lc"]];
        return cell;
    }
    else if(indexPath.row == 8){
        KaiJiangFiveCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier2];
          cell.pushflag = 1;
        cell.titleName.text = @"11选5";
        cell.timeTitle.text =  [date_formatter stringFromDate:[NSDate date]];

        cell.numTitle.text = [NSString stringWithFormat:@"%@期",[[self getTimeAndRandom]substringToIndex:12]];
        [cell.imageName setImage:[UIImage imageNamed:@"icon_11x5"]];
        return cell;
    }else{
        return nil;
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 85;
}

-(NSString*)getTimeAndRandom{
    int iRandom=arc4random();
    if (iRandom<0) {
        iRandom=-iRandom;
    }
    
    NSDateFormatter *tFormat=[[NSDateFormatter alloc] init];
    [tFormat setDateFormat:@"yyyyMMdd"];
    NSString *tResult=[NSString stringWithFormat:@"%@%d",[tFormat stringFromDate:[NSDate date]],iRandom];
    return tResult;
}


-(NSString*)getYestTimeAndRandom{
    int iRandom=arc4random();
    if (iRandom<0) {
        iRandom=-iRandom;
    }
    
    NSDateFormatter *tFormat=[[NSDateFormatter alloc] init];
    [tFormat setDateFormat:@"yyyyMMdd"];
    NSTimeInterval  oneDay = -24*60*60*1;  //1天的长度
    NSDate* theDate;
    theDate = [[NSDate date]initWithTimeIntervalSinceNow: oneDay*1 ];

    NSString *tResult=[NSString stringWithFormat:@"%@%d",[tFormat stringFromDate:theDate],iRandom];
    return tResult;
}

-(NSString*)getYYestTimeAndRandom{
    int iRandom=arc4random();
    if (iRandom<0) {
        iRandom=-iRandom;
    }
    
    NSDateFormatter *tFormat=[[NSDateFormatter alloc] init];
    [tFormat setDateFormat:@"yyyyMMdd"];
    NSDate* theDate;
        NSTimeInterval  oneDay = -24*60*60*1;  //1天的长度
    theDate = [[NSDate date]initWithTimeIntervalSinceNow: oneDay*2 ];
    
    NSString *tResult=[NSString stringWithFormat:@"%@%d",[tFormat stringFromDate:theDate],iRandom];
    return tResult;
}
@end
